<template>
  <div class="app-container">
    <el-row :gutter="20">
        <el-col :span="20" :xs="24">
            <el-row :gutter="10" class="mb8">
               <el-col :span="1.5">
                  <el-button
                     type="primary"
                     plain
                     icon="Upload"
                     @click="handleMemberImport"
                     v-hasPermi="['ndpf:migration:oper']"
                  >成员用户迁移导入</el-button>
               </el-col>
               <el-col :span="1.5">
                  <el-button
                     type="success"
                     plain
                     icon="Download"
                     @click="handleMemberExport"
                     v-hasPermi="['ndpf:migration:oper']"
                  >成员用户导出</el-button>
               </el-col>
               <el-col :span="1.5">
                  <el-button
                     type="warning"
                     plain
                     icon="Upload"
                     @click="handleTeamImport"
                     v-hasPermi="['ndpf:migration:oper']"
                  >团队用户迁移导入</el-button>
               </el-col>
              <el-col :span="1.5">
                  <el-button
                     type="success"
                     plain
                     icon="Download"
                     @click="handleTeamExport"
                     v-hasPermi="['ndpf:migration:oper']"
                  >团队用户导出</el-button>
               </el-col>
               <el-col :span="1.5">
                  <el-button
                     v-if="false"
                     type="success"
                     plain
                     icon="Upload"
                     @click="handleProjectImport"
                     v-hasPermi="['ndpf:migration:oper']"
                  >项目迁移导入</el-button>
               </el-col>
            </el-row>
        </el-col>
    </el-row>

    <!-- 用户导入对话框 -->
    <el-dialog :title="uploadMember.title" v-model="uploadMember.open" width="400px" append-to-body>
        <el-upload
        ref="uploadMemberRef"
        :limit="1"
        accept=".xlsx"
        :headers="uploadMember.headers"
        :action="uploadMember.url + '?updateSupport=' + uploadMember.updateSupport"
        :disabled="uploadMember.isUploading"
        :on-progress="handleMemberFileUploadProgress"
        :on-success="handleMemberFileSuccess"
        :auto-upload="false"
        drag
        >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <template #tip>
            <div class="el-upload__tip text-center">
                <span>仅允许导入xlsx格式文件。</span>
            </div>
        </template>
        </el-upload>
        <template #footer>
        <div class="dialog-footer">
            <el-button type="primary" @click="submitMemberFileForm">确 定</el-button>
            <el-button @click="uploadMember.open = false">取 消</el-button>
        </div>
        </template>
    </el-dialog>



    <!-- 用户导入对话框 -->
    <el-dialog :title="uploadTeam.title" v-model="uploadTeam.open" width="400px" append-to-body>
        <el-upload
        ref="uploadTeamRef"
        :limit="1"
        accept=".xlsx"
        :headers="uploadTeam.headers"
        :action="uploadTeam.url + '?updateSupport=' + uploadTeam.updateSupport"
        :disabled="uploadTeam.isUploading"
        :on-progress="handleTeamFileUploadProgress"
        :on-success="handleTeamFileSuccess"
        :auto-upload="false"
        drag
        >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <template #tip>
            <div class="el-upload__tip text-center">
                <span>仅允许导入xlsx格式文件。</span>
            </div>
        </template>
        </el-upload>
        <template #footer>
        <div class="dialog-footer">
            <el-button type="primary" @click="submitTeamFileForm">确 定</el-button>
            <el-button @click="uploadTeam.open = false">取 消</el-button>
        </div>
        </template>
    </el-dialog>

  </div>
</template>

<script setup name="migration">
import { getToken } from "@/utils/auth";
const { proxy } = getCurrentInstance();

const data = reactive({
  form: {},
  queryParams: {
   
  }
});

const { queryParams } = toRefs(data);


/*** 成员用户导入参数 */
const uploadMember = reactive({
  // 是否显示弹出层（成员用户导入）
  open: false,
  // 弹出层标题（成员用户导入）
  title: "成员用户导入",
  // 是否禁用上传
  isUploading: false,
  // 是否更新已经存在的用户数据
  updateSupport: 0,
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/ndpf/migration/importMembertData"
});



/*** 团队用户导入参数 */
const uploadTeam = reactive({
  // 是否显示弹出层（团队用户导入）
  open: false,
  // 弹出层标题（团队用户导入）
  title: "团队用户导入",
  // 是否禁用上传
  isUploading: false,
  // 是否更新已经存在的用户数据
  updateSupport: 0,
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/ndpf/migration/importTeamData"
});


// 成员导入模块Start

/** 导入按钮操作 */
function handleMemberImport() {
uploadMember.title = "成员用户导入";
  uploadMember.open = true;
};

/**文件上传中处理 */
const handleMemberFileUploadProgress = (event, file, fileList) => {
  uploadMember.isUploading = true;
};
/** 文件上传成功处理 */
const handleMemberFileSuccess = (response, file, fileList) => {
  uploadMember.open = false;
  uploadMember.isUploading = false;
  proxy.$refs["uploadMemberRef"].handleRemove(file);
  proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
};
/** 提交上传文件 */
function submitMemberFileForm() {
  proxy.$refs["uploadMemberRef"].submit();
};

// 成员导入模块End

// 成员导出模块Start

/** 导出按钮操作 */
function handleMemberExport() {
  proxy.download("ndpf/migration/exportMembertData", {
    ...queryParams.value,
  },`member_${new Date().getTime()}.xlsx`);
};

// 成员导出模块End


// 团队导入模块Start
/** 导入按钮操作 */
function handleTeamImport() {
uploadTeam.title = "团队用户导入";
  uploadTeam.open = true;
};

/**文件上传中处理 */
const handleTeamFileUploadProgress = (event, file, fileList) => {
  uploadMember.isUploading = true;
};
/** 文件上传成功处理 */
const handleTeamFileSuccess = (response, file, fileList) => {
  uploadTeam.open = false;
  uploadTeam.isUploading = false;
  proxy.$refs["uploadTeamRef"].handleRemove(file);
  proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
};
/** 提交上传文件 */
function submitTeamFileForm() {
  proxy.$refs["uploadTeamRef"].submit();
};

// 团队导入模块End

// 团队导出模块Start

/** 导出按钮操作 */
function handleTeamExport() {
  proxy.download("ndpf/migration/exportTeamData", {
    ...queryParams.value,
  },`member_${new Date().getTime()}.xlsx`);
};

// 团队导出模块End

</script>

<style scoped>


</style>